<link rel="stylesheet" type="text/css" href="/assets/third-party/datatables/css/jquery.dataTables.min.css">
<link rel="stylesheet" type="text/css" href="/assets/css/dataTables.bootstrap.css">
<link rel="stylesheet" type="text/css" href="/assets/third-party/bootstrap-datetimepicker-master/css/bootstrap-datetimepicker.min.css">

<style type="text/css">
    .il{
        display: inline;
    }
</style>

<div class="container" style="margin-top: 60px;">
    <div class="row">
        <div class="col-lg-12">
            <form action="/admin/order">
                <input type="text" name="start_at" placeholder="选课起始时间" value="<?php echo \Input::get('start_at', ''); ?>" class="form-control il" style="width: 160px;" role="datetime"> 
                - <input type="text" name="end_at" placeholder="选课结束时间" value="<?php echo \Input::get('end_at', ''); ?>" class="form-control il" style="width: 160px;" role="datetime">             
                <button type="submit" class="btn btn-info"> <i class="fa fa-search"></i> 查询</button>
                <a href="/admin/order/create" class="btn btn-success"> <i class="fa fa-plus"></i> 添加选课 </a>
                <!--<a href="#" class="btn btn-success"> <i class="fa fa-plus"></i> 全选 </a>
                <a href="#" class="btn btn-danger"> <i class="fa fa-plus"></i> 批量删除 </a>
                <a href="#" class="btn btn-danger"> <i class="fa fa-plus"></i> 刷新 </a>-->
            </form>
        </div>
    </div>
    <div class="row" style="margin-top: 10px;">
        <div class="col-lg-12">
            <div class="panel panel-default">
                <div class="panel-heading">
                    选课记录
                </div>
                <!-- /.panel-heading -->
                <div class="panel-body">
                    <table class="table table-bordered table-hover">
                        <thead>
                            <tr>
                                <th>选课号</th>
                                <th>所选课程</th>
                                <th>选课日期</th>
                                <th>选课状态</th>
                                <th>缴费方式</th>
                                <th>总金额</th>
                                <th>操作</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php foreach ($items as $key => $value) { ?>
                            <tr data-id="<?php echo $value->id; ?>">
                                <td><?php echo $value->order_no; ?></td>
                                <td><?php echo $value->order_name; ?></td>
                                <td><?php echo date('Y-m-d H:i:s', $value->created_at); ?></td>
                                <td><?php echo \Model_Order::$_maps['status'][$value->order_status]; ?></td>
                                <td><?php echo \Model_Order::$_maps['payment'][$value->payment_type]; ?></td>
                                <td>
                                    <span style="font-size: 13px; color:#f60;"><?php echo $value->original_money; ?></span>
                                    <span style="text-decoration:line-through"><?php echo $value->money; ?></span>
                                </td>
                                <td>
                                    <a class="btn btn-sm btn-info" role="edit"> <i class="fa fa-pencil-square-o"></i> 编辑</a>
                                    <a data-toggle="modal" data-target="#confirmModal" class="btn btn-sm btn-danger"> <i class="fa fa-trash-o"></i> 删除</a>
                                    <!--<a href="#" class="btn btn-sm btn-success"> <i class="fa fa-arrow-up"></i> 置顶</a>-->
                                </td>
                            </tr>
                            <?php } ?>
                            
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>


<!-- 确认删除模态框 -->
<div class="modal fade" id="confirmModal" tabindex="-1" role="dialog" aria-labelledby="confirmModalTitle" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-body">
                <div class="alert alert-warning">
                    <strong>确定删除？</strong>
                    <p>删除该记录，该记录将无法被查找到!</p>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal"> 取消 </button>
                <button type="button" id="btnConfirm" class="btn btn-danger"> 确定 </button>
            </div>
        </div>
    </div>
</div>

<script type="text/javascript" src="/assets/third-party/datatables/js/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="/assets/js/dataTables.bootstrap.js"></script>
<script type="text/javascript">
    var flag = false;

    $(function(){
        $('.table').dataTable({
            "oLanguage": {
                "sLengthMenu": "每页显示 _MENU_ 条记录",
                "sZeroRecords": "很抱歉，未找到相关数据",
                "sInfo": "从 _START_ 至 _END_ /共 _TOTAL_ 条数据",
                "sInfoEmpty": "没有符合条件的数据",
                "sInfoFiltered": "(从 _MAX_ 条数据中检索)",
                "sSearch": "搜索：",
                "oPaginate": {  
                    "sFirst": "首页",  
                    "sPrevious": "上一页",
                    "sNext": "下一页",
                    "sLast": "末页"
                }  
            },
            fnDrawCallback: function(){

                if(window.flag == false){
                    window.flag = true;
                    var index = localStorage.getItem('pagination_index');
                    localStorage.removeItem('pagination_index');
                    if( ! index){
                        index = 1;
                    }
                    index -= 1;

                    $('.table').dataTable().fnPageChange(index);
                    
                }
            }
        });

        $('table').delegate('a[data-target="#confirmModal"]', 'click', function(){
            $('#btnConfirm').attr('data-id', $(this).parent().parent().attr('data-id'));            
        });

        $('table').delegate('a[role="edit"]', 'click', function(){
            localStorage.setItem('pagination_index', $('.pagination .active').find('a').text());
            window.location.href = "/admin/node/edit/" + $(this).parents('tr').attr('data-id');
        });

        $('#btnConfirm').click(function(){
            window.location.href = "/admin/node/delete/" + $(this).attr('data-id');
        });
    });
</script>

<script type="text/javascript" src="/assets/third-party/bootstrap-datetimepicker-master/js/bootstrap-datetimepicker.min.js"></script>
<script type="text/javascript" src="/assets/third-party/bootstrap-datetimepicker-master/js/locales/bootstrap-datetimepicker.zh-CN.js" charset="UTF-8"></script>
<script type="text/javascript">
$(function(){
    $('input[role="datetime"]').datetimepicker({
        language: 'zh-CN'
    });
});
</script>